// user/project/pay.js
var home = require("../../utils/util.js");
var url = home.home;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    page:1,
    listData:[],
    orderStatus:0,
    show:false,
    bgcolor: home.getKey('bgcolor'),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      active: options.active
    })
  },

  //获取预约列表
  getGoodsList(){
    let that = this;
    wx.request({
      url: url + 'app/prebookList4Member',
      data:{
        storeId:home.getKey('storeId'),
        memberId:home.getKey('userId'),
        orderStatus:that.data.orderStatus
      },
      method: 'POST',
      header: {
        "content-type": "application/json", // 默认
      },
      success:function (res) {
        if (res.data.code == 200) {
          let listData = [];
          // for (let i = 0; i < res.data.result.length; i++) {
          //   for (let j = 0; j < res.data.result[i].commodityList.length; j++) {
          //     if (res.data.result[i].commodityList[j].pic) {
          //       let pic = res.data.result[i].commodityList[j].pic.split(',');
          //       res.data.result[i].commodityList[j].pic = 'https://kyz.fbhkj.com//' + pic[0];
          //     }
          //   }
          // }
          listData = res.data.result;
          let show = false;
          if (listData.length == 0) {
            show = true;
          }
          that.setData({listData:listData,show:show});
        } else {
          wx.showToast({
            title: '获取失败',
            icon: 'none'
          })
        }
      }
    })
  },

  onClose(e){
    let that = this;
    wx.request({
      url: url + 'app/changeStatus',
      data:{
        recordId:e.currentTarget.dataset.orderid,
        storeId:home.getKey('storeId'),
        status: 2
      },
      method: 'GET',
      header: {
        "content-type": "application/json", // 默认
      },
      success:function (res) {
        if (res.data.code == 200) {
          home.wxMessage('已取消');
        } else {
          home.wxMessage(res.data.message,'none');
        }
        that.getGoodsList();
      }
    })
  },

  onChange(e) {
    console.log(e);
    this.setData({
      orderStatus:e.detail.index,
      active:e.detail.index,
      page:1,
      listData:[]
    });
    this.getGoodsList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getGoodsList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // let page = this.data.page;
    // this.setData({page:++page});
    // this.getGoodsList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})